package cn.wzb.hrm.web.controller;

import cn.wzb.hrm.doc.CourseDoc;
import cn.wzb.hrm.query.CourseQuery;
import cn.wzb.hrm.repository.CourseESRepository;
import cn.wzb.hrm.service.ESService;
import cn.wzb.hrm.util.AjaxResult;
import cn.wzb.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ESController {

    @Autowired
    private CourseESRepository courseESRepository;

    @Autowired
    private ESService esService;

    //保存课程--参数是CourseDoc 文档对象
    @RequestMapping(value = "/es/onLineCourse",method = RequestMethod.POST)
    public AjaxResult onLineCourse(@RequestBody CourseDoc courseDoc){
        //调用repository保存
        courseESRepository.save(courseDoc);
        return AjaxResult.me();
    }

    //删除课程--参数是CourseDoc 文档对象
    @RequestMapping("/es/delete/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        //调用repository保存
        courseESRepository.deleteById(id);
        return AjaxResult.me();
    }
    //查询课程
    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public PageList<CourseDoc> searchCourse(@RequestBody CourseQuery courseQuery){
        return esService.searchCourse(courseQuery);
    }
}
